package cn.sirun.com.fca.account.uitl;

import android.text.TextUtils;

import com.tencent.cloud.iov.util.storage.TXSharedPreferencesUtils;

import cn.sirun.com.fca.account.model.login.PersonalInfo;
import cn.sirun.com.fca.account.service.LoginManager;

/**
 * @author vinsonhuang
 * @date 2018/10/10
 */
public class PersonalInfoUtils {

    public static void savePersonalInfo(PersonalInfo personalInfo) {
        if (null != personalInfo) {
            TXSharedPreferencesUtils.setValue(LoginManager.PERSONAL_INFO_CACHE_KEY,
                    GsonHelper.getGson().toJson(personalInfo));
        } else {
            TXSharedPreferencesUtils.remove(LoginManager.PERSONAL_INFO_CACHE_KEY);
        }
    }

    public static PersonalInfo getPersonalInfo() {
        String personalInfoString = TXSharedPreferencesUtils.getValue(
                LoginManager.PERSONAL_INFO_CACHE_KEY);
        if (TextUtils.isEmpty(personalInfoString)) {
            return null;
        }
        return GsonHelper.getGson().fromJson(personalInfoString, PersonalInfo.class);
    }

}
